package sliding_window;

public class lengthOfLongestSubstring {
    public int lengthOfLongestSubstring(String s) {
        int[] hash = new int[128];
        int n = s.length();
        int ret = 0;
        for(int left = 0,right = 0;right < n;right++) {
            //进窗口
            hash[s.charAt(right)]++;
            //判断
            if(hash[s.charAt(right)] > 1) {
                //出窗口
                while(hash[s.charAt(right)] >= 2) {
                    hash[s.charAt(left)]--;
                    left++;
                }
            }
            //更新结果
            ret = Math.max(ret,right-left+1);
        }
        return ret;

    }
}
